package cn.com.bs.srmp;

import java.util.List;
import java.util.Set;

import org.apache.maven.plugin.AbstractMojo;
import org.apache.maven.plugins.annotations.Execute;
import org.apache.maven.plugins.annotations.LifecyclePhase;
import org.apache.maven.plugins.annotations.Mojo;
import org.apache.maven.plugins.annotations.Parameter;

import com.alibaba.fastjson.JSON;

import cn.com.bs.srmp.conf.PluginContext;
import cn.com.bs.srmp.runner.RunnerWriteFile;
import lombok.Data;
import lombok.extern.slf4j.Slf4j;


/**
 * @Author mic
 * @Date 2022-04-14 16:31
 */
@Slf4j
@Data
@Mojo(name = "service-reference", defaultPhase = LifecyclePhase.PACKAGE)
public class ServiceReferencePlugin extends AbstractMojo {


    /**
     * 组件名称
     */
    @Parameter(property = "componentName")
    private String componentName;

    /**
     * 项目路径
     **/
    @Parameter(property = "projectPath")
    private String projectPath;

    /**
     * 排除模块模糊 模块名
     */
    @Parameter(property = "excludeModuleFuzzyNames")
    private Set<String> excludeModuleFuzzyNames;

    /**
     * 指定模块模糊 模块名
     */
    @Parameter(property = "specifyModuleFuzzyNames")
    private List<String> specifyModuleFuzzyNames;

    /**
     * 排除jar匹配
     */
    @Parameter(property = "excludeJarFuzzyNames")
    private List<String> excludeJarFuzzyNames;

    /**
     * 文件输出路径
     */
    @Parameter(property = "fileOutputPath")
    private String fileOutputPath;

    /**
     * 当前项目 feign 包绝对路径
     */
    @Parameter(property = "feignApiPaths")
    private List<String> feignApiPaths;

    /**
     * 排除当前项目feign 接口包路径
     */
    @Parameter(property = "excludeFeignReferencePaths")
    private List<String> excludeFeignApiReferencePaths;

    /**
     * 是否删除合并文件
     */
    @Parameter(property = "deleteMergeFile")
    private Boolean deleteMergeFile;

    /**
     * 开关
     */
    @Parameter(property = "genRelySwitch")
    private Boolean genRelySwitch;

    @Override
    public void execute() {
        if (genRelySwitch != null && !genRelySwitch) {
            log.info("genRelySwitch: {} ", genRelySwitch);
            return;
        }
        PluginContext pluginContext = PluginContext.builder()
                .projectPath(projectPath)
                .excludeModuleFuzzyNames(excludeModuleFuzzyNames)
                .specifyModuleFuzzyNames(specifyModuleFuzzyNames)
                .excludeJarFuzzyNames(excludeJarFuzzyNames)
                .feignApiPaths(feignApiPaths)
                .excludeFeignApiReferencePaths(excludeFeignApiReferencePaths)
                .fileOutputPath(fileOutputPath)
                .componentName(componentName)
                .deleteMergeFile(deleteMergeFile)
                .build();
        log.info("confInfo: {} ", JSON.toJSONString(pluginContext));
        new RunnerWriteFile(pluginContext).run();
    }

}
